<% email = SharedHelpers.get_assigns_or_param(assigns, "email") %>
<% target = SharedHelpers.get_assigns_or_param(assigns, "to", "news") %>

<%= form_tag Routes.person_path(@conn, :subscribe), id: "subscribe", class: "auth form form--full_width" do %>
  <input name="to" type="hidden" value="<%= target %>">

  <div class="form-element_wrap">
    <div class="form-element">
      <label>Email<span>*</span></label>
      <input
        name="email"
        value="<%= email %>"
        placeholder="grace@hopper.com"
        aria-label="grace@hopper.com"
        autocapitalize="none"
        required
      <%= if !email do %>
        autofocus=true
      <% end %>
      />
    </div>
  </div>

  <div class="form-element_wrap">
    <div class="form-element">
      <label>Name</label>
      <input
        name="name"
        value='<%= SharedHelpers.get_assigns_or_param(assigns, "name") %>'
        placeholder="Grace Hopper"
      <%= if email do %>
        autofocus=true
      <% end %>
      />
    </div>
  </div>

  <div class="form-element_wrap">
    <div class="form-element" style="text-align: center;">
      <script src="https://challenges.cloudflare.com/turnstile/v0/api.js" async defer></script>
      <div class="cf-turnstile" data-sitekey="0x4AAAAAAAAnzevzjdGT8igM" style="display: inline-block;"></div>
    </div>
  </div>

<%= if target != "news" do %>
  <div class="form-checklist">
    <div class="form-checklist-item">
      <label>
        <input name="news_subscribe" type="checkbox">
        <span class="form-checklist-item-box"></span>
        <span class="form-checklist-item-text">Also sign me up for Changelog News!</span>
      </label>
    </div>
  </div>
<% end %>

  <div class="form-submit">
    <div class="form-submit-note">
      <div>Already a subscriber? <em><%= link("Sign in", to: Routes.sign_in_path(@conn, :new), title: "") %></em></div>
    </div>

    <input type="submit" value="Subscribe Now">
  </div>
<% end %>
